import 'package:changxindianzishangwu/pages/login/country_phone_page.dart';
import 'package:changxindianzishangwu/util/toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class BindPhoneInitPage extends StatefulWidget {
  BindPhoneInitPage({Key key}) : super(key: key);

  @override
  _BindPhoneInitPageState createState() => _BindPhoneInitPageState();
}

class _BindPhoneInitPageState extends State<BindPhoneInitPage> {
  var inputText;
  var phoneCountry = "+86";
  var data;

  @override
  Widget build(BuildContext context) {
    _goTo() async {
      await Get.to(() => CountryPhonePage());
    }

    if (Get.arguments == null) {
      phoneCountry = "+86";
    } else {
      phoneCountry = Get.arguments;
    }
    return GestureDetector(
      onTap: () {
        //收起键盘
        FocusScope.of(context).requestFocus(FocusNode());
      },
      child: Scaffold(
        appBar: AppBar(
          elevation: 0,
          title: Text(
            "绑定手机号",
            style: TextStyle(
              fontSize: ScreenUtil().setSp(16),
              fontFamily: "PingFang SC",
              color: Color.fromRGBO(51, 51, 51, 1),
            ),
          ),
          centerTitle: true,
        ),
        backgroundColor: Colors.white,
        body: SingleChildScrollView(
          child: Container(
            color: Colors.white,
            child: Column(
              children: <Widget>[
                Container(
                  height: 25.h,
                  width: ScreenUtil().setWidth(120),
                  margin: EdgeInsets.only(
                      top: ScreenUtil().setHeight(45),
                      right: ScreenUtil().setWidth(375 - 16 - 120)),
                  child: Text(
                    "为了账号安全请绑定你本人使用的手机号码",
                    style: TextStyle(
                      fontSize: ScreenUtil().setSp(18),
                      fontFamily: "PingFang SC",
                      color: Color.fromRGBO(51, 51, 51, 1),
                    ),
                  ),
                ),
                Container(
                  height: ScreenUtil().setHeight(25),
                  width: ScreenUtil().setWidth(219),
                  margin: EdgeInsets.only(
                      right: ScreenUtil().setWidth(375 - 16 - 219),
                      top: ScreenUtil().setHeight(10)),
                  child: Text(
                    "未注册手机号一键登陆后将自动创建账号",
                    style: TextStyle(
                      fontSize: ScreenUtil().setSp(12),
                      fontFamily: "PingFang SC",
                      color: Color.fromRGBO(153, 153, 153, 1),
                    ),
                  ),
                ),
                Container(
                  height: ScreenUtil().setHeight(25),
                  width: ScreenUtil().setWidth(219),
                  margin: EdgeInsets.only(
                      right: ScreenUtil().setWidth(375 - 16 - 219),
                      top: ScreenUtil().setHeight(30)),
                  child: Text(
                    "手机号码",
                    style: TextStyle(
                      fontSize: ScreenUtil().setSp(13),
                      fontFamily: "PingFang SC",
                      color: Color.fromRGBO(85, 85, 85, 1),
                    ),
                  ),
                ),
                Container(
                  child: Row(
                    children: <Widget>[
                      SizedBox(
                        width: ScreenUtil().setWidth(16),
                      ),
                      InkWell(
                        onTap: () {
                          _goTo();
                        },
                        child: Container(
                          child: Text(phoneCountry),
                        ),
                      ),
                      SizedBox(
                        width: ScreenUtil().setWidth(16),
                      ),
                      InkWell(
                          onTap: () {
                            _goTo();
                          },
                          child: Image.asset("images/下拉.png")),
                      SizedBox(
                        width: ScreenUtil().setWidth(7),
                      ),
                      Expanded(
                        child: TextField(
                          onChanged: (text) {
                            inputText = text;
                          },
                          keyboardType: TextInputType.number,
                          cursorColor: Colors.greenAccent,
                          decoration: InputDecoration(
                            border: InputBorder.none,
                            hintText: "请输入新手机号码",
                            hintStyle: TextStyle(
                              fontSize: ScreenUtil().setSp(13),
                              color: Color.fromRGBO(153, 153, 153, 1),
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                Divider(
                  indent: ScreenUtil().setWidth(16),
                  endIndent: ScreenUtil().setWidth(14),
                  color: Color.fromRGBO(232, 232, 232, 1),
                  height: ScreenUtil().setHeight(1),
                  thickness: ScreenUtil().setHeight(1),
                ),
                InkWell(
                  onTap: () {
                    print("发送验证码");
                    if (inputText == null) {
                      showToast("手机号码不能为空");
                    } else if (inputText != null && inputText.length > 11 ||
                        inputText.length < 11) {
                      showToast("请输入正确的手机号");
                    } else if (inputText.length == 11) {
                      //do some
                    }
                  },
                  child: Container(
                    height: ScreenUtil().setHeight(44),
                    width: ScreenUtil().setWidth(300),
                    margin: EdgeInsets.only(
                        right: ScreenUtil().setWidth(75 / 2),
                        left: ScreenUtil().setWidth(75 / 2),
                        top: ScreenUtil().setHeight(60)),
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                        color: Color.fromRGBO(0, 220, 169, 1),
                        borderRadius:
                            BorderRadius.circular(ScreenUtil().radius(5))),
                    child: Text(
                      "下一步",
                      style: TextStyle(
                          fontSize: ScreenUtil().setSp(15),
                          color: Colors.white,
                          fontFamily: "PingFang SC"),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
        resizeToAvoidBottomInset: false,
      ),
    );
  }
}
